
//
//  XZNotificationCell.m
//  优学荟管理系统
//
//  Created by edz on 2018/1/22.
//  Copyright © 2018年 星道三好. All rights reserved.
//

#import "XZNotificationCell.h"

@interface XZNotificationCell()

@property (nonatomic, strong) UILabel *title;

@property (nonatomic, strong) UILabel *curteTime;

@property (nonatomic, strong) UIButton *seeDetail;

@property (nonatomic, strong) UIView *redView;

@end


@implementation XZNotificationCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //取消选中效果
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setModel:(XZNotificationModel *)model {
    _model = model;
    
    [_seeDetail SG_imagePositionStyle:(SGImagePositionStyleRight) spacing:5];
    _title.text = model.title;
    _curteTime.text =  [NSString stringWithFormat:@"通告时间：%@",model.createTime];
    
    // 等于0 就是没看 
//    _redView.hidden = [model.isRead isEqualToNumber:@0] ? NO : YES;
}


- (void)setupUI {
    
    self.contentView.backgroundColor = ColorRGB(245, 245, 245);
    UIView *backRandView = [[UIView alloc] init];
    backRandView.backgroundColor = [UIColor whiteColor];
    
//    _redView = [[UIView alloc] init];
//    _redView.backgroundColor = [UIColor redColor];
//    _redView.layer.cornerRadius = 2;
//    _redView.layer.masksToBounds = YES;
    
    
    UIImageView *iconImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"list_icon_news_default"]];
    
    _title = [[UILabel alloc] init];
    _curteTime.font = [UIFont systemFontOfSize:15];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = ColorRGB(245, 245, 245);
    
    _curteTime = [[UILabel alloc] init];
    _curteTime.textColor = ColorRGB(150, 149, 149);
    _curteTime.font = [UIFont systemFontOfSize:14];
    
    _seeDetail = [[UIButton alloc] init];
    [_seeDetail setImage:[UIImage imageNamed:@"icon_organization_more_default"] forState:(UIControlStateNormal)];
    [_seeDetail setTitle:@"查看详情" forState:(UIControlStateNormal)];
    [_seeDetail setTitleColor:ColorRGB(150, 149, 149) forState:(UIControlStateNormal)];
    [_seeDetail addTarget:self action:@selector(seeDetails:) forControlEvents:UIControlEventTouchUpInside];
    _seeDetail.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [self.contentView addSubview:backRandView];
    [backRandView addSubview:_redView];
    [backRandView addSubview:iconImage];
    [backRandView addSubview:_title];
    [backRandView addSubview:lineView];
    [backRandView addSubview:_curteTime];
    [backRandView addSubview:_seeDetail];
    
    
    
    [backRandView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.left.right.bottom.equalTo(self.contentView);
    }];
    
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backRandView).offset(45);
        make.left.equalTo(backRandView).offset(15);
        make.right.equalTo(backRandView).offset(-15);
        make.height.offset(1);
    }];
    
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lineView).offset(-12);
        make.left.equalTo(lineView);
    }];
    
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconImage);
        make.left.equalTo(iconImage.mas_right).offset(15);
        make.width.offset(SCREEN_WIDTH/1.8);
    }];
    
    [_seeDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.title);
        make.right.equalTo(lineView);
    }];
    
//    [_redView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(_seeDetail.mas_top).offset(-4);
//        make.right.equalTo(_seeDetail);
//        make.size.mas_equalTo(CGSizeMake(4, 4));
//    }];
    
    [_curteTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView).offset(12);
        make.left.equalTo(lineView);
    }];

}

#pragma mark - 查看详情的回调
- (void)seeDetails:(UIButton *)sender {
    if (_CallBack) {
        _CallBack(self.model.ID);
    }
}

@end
